﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Hongapo_Common;

public partial class deliver : Hongapo_Services.UIPage
{
    private Hongapo_Model.Product.Product model = new Hongapo_Model.Product.Product();
    private Hongapo_Services.Product.Product bll = new Hongapo_Services.Product.Product();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.hiddenOrderNo.Value = "N" + DateTime.Now.ToString("yyMMddHHmmfff");
            LoadDropDowList();
        }
    }

    #region 加载商城
    private void LoadDropDowList()
    {
        Hongapo_Services.Mall.Mall bll_mall = new Hongapo_Services.Mall.Mall();
        this.ddlMall.DataSource = bll_mall.GetList(" isopen=1 order by sort");
        this.ddlMall.DataValueField = "ID";
        this.ddlMall.DataTextField = "Title";
        this.ddlMall.DataBind();
    }
    #endregion


    #region 上传产品
    private void Add()
    {
        string orderno = this.hiddenOrderNo.Value;
        try
        {
            model.Clicks = 0;
            model.Createdate = DateTime.Now;
            model.Favours =0;
            model.Grade = 0;
            model.GradeClicks = 0;
            model.Opposes = 0;
            model.InfoDesc = this.txtInfo.Value;
            model.Isopen = 1;
            model.IsPay = 0;
            model.LinkUrl = this.txtUrlAddress.Text;
            model.MemberID = 1;
            model.MID = TypeConvert.ToInt32(this.ddlMall.SelectedValue);
            model.OldPrice = TypeConvert.ToDecimal(this.txtCostPrice.Text);
            model.OrderNo = this.hiddenOrderNo.Value;
            model.RealPrice = TypeConvert.ToDecimal(this.txtRealPrice.Text);
            model.Remark = "";
            model.Title = this.txtTile.Text;
            model.Summary = StringUtils.CutString(StringUtils.FilterHtml(this.txtInfo.Value), 160);
            model.IPAdd = objectHandlers.GetIP();
            model.DeliVerName = "前台投递";
            model.DeliVerContact = "前台投递";
            bll.Add(model);


            new Hongapo_Services.Product.ProductImage().UpdateImageIsopen(orderno);// 修改图片为有效
            this.Show("上传成功！", "index.aspx");
        }
        catch (Exception ex)
        {
            new Hongapo_Services.Product.ProductImage().Delete(orderno);
            throw;
        }
    }
    #endregion
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        Add();
    }
}
